using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Visual_Hello_World
{
    public partial class nameTextBox : Form
    {
        public nameTextBox()
        {
            InitializeComponent();
        }

        private void sayHelloButton_Click(object sender, EventArgs e)
        {
            label1.Text = "Hello " + textBox1.Text + "\r\n"
                + "How are you today?";

            showDirectory();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = "Ah, I see you are typing";
            listBox1.ClearSelected();

        }

        private void showDirectory()
        {
            //This is to show all the local files
            // You can also use System.Environment.GetLogicalDrives to 
            // obtain names of all logical drives on the computer.
            System.IO.DriveInfo di = new System.IO.DriveInfo(@"D:\");
            List<string> MyList = new List<string>();
            MyList.Add("HELLO");
            MyList.Add("WORLD");
            MyList.Add("Total Free Space: " + di.TotalFreeSpace.ToString());
            MyList.Add("Drive Label: " + di.VolumeLabel);
            //Console.WriteLine(di.TotalFreeSpace);
            //Console.WriteLine(di.VolumeLabel);

            // Get the root directory and print out some information about it.
            System.IO.DirectoryInfo dirInfo = di.RootDirectory;
            //Console.WriteLine(dirInfo.Attributes.ToString());

            MyList.Add("Root Dir: " + dirInfo.Attributes.ToString());
            // Get the files in the directory and print out some information about them.
            System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.*");


            foreach (System.IO.FileInfo fi in fileNames)
            {
                Console.WriteLine("{0}: {1}: {2}", fi.Name, fi.LastAccessTime, fi.Length);
                MyList.Add("File Name: " + fi.Name
                    + " File Last ACcessed: " + fi.LastAccessTime
                    + " File Length: " + fi.Length);
            }

            // Get the subdirectories directly that is under the root. 
            // See "How to: Iterate Through a Directory Tree" for an example of how to
            // iterate through an entire tree.
            System.IO.DirectoryInfo[] dirInfos = dirInfo.GetDirectories("*.*");

            foreach (System.IO.DirectoryInfo d in dirInfos)
            {
                Console.WriteLine(d.Name);
                MyList.Add("Directory Listing: "
                 + d.Name);
            }

            // The Directory and File classes provide several static methods 
            // for accessing files and directories. 

            // Get the current application directory. 
            string currentDirName = System.IO.Directory.GetCurrentDirectory();
            Console.WriteLine(currentDirName);

            // Get an array of file names as strings rather than FileInfo objects. 
            // Use this method when storage space is an issue, and when you might 
            // hold on to the file name reference for a while before you try to access 
            // the file. 
            string[] files = System.IO.Directory.GetFiles(currentDirName, "*.txt");

            foreach (string s in files)
            {
                // Create the FileInfo object only when needed to ensure 
                // the information is as current as possible.
                System.IO.FileInfo fi = null;
                try
                {
                    fi = new System.IO.FileInfo(s);
                }
                catch (System.IO.FileNotFoundException e)
                {
                    // To inform the user and continue is 
                    // sufficient for this demonstration. 
                    // Your application may require different behavior.
                    Console.WriteLine(e.Message);
                    continue;
                }
                Console.WriteLine("{0} : {1}", fi.Name, fi.Directory);
            }

            //Populate my list box
            listBox1.DataSource = MyList;

        }

    }
}